package com.msc.cili.web.viewcontroller.visit;

import com.msc.cili.common.api.Result;
import com.msc.cili.common.utils.IPUtil;
import com.msc.cili.service.ip.IpAddressService;
import com.msc.cili.web.viewcontroller.visit.vo.IpInfoVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 骑蜗牛的羊
 * @date 2023/4/30 0:22
 * <p>Ip</p>
 */
@RestController
public class IpRegionInfoController {

    @GetMapping("/getIpInfo")
    public Result getRegionInfoByIp(@RequestParam(value = "ip", defaultValue = "127.0.0.1") String ip,
                                    HttpServletRequest request) {
        IpInfoVo res=new IpInfoVo();
        String ipAddr = IPUtil.getIpAddr(request);
        String ipSource = IpAddressService.getCityInfo(ipAddr);
        res.setIp(ipAddr);
        res.setRegionName(ipSource);
        return Result.succ(res);
    }
}
